package com.scs.application.modules.cert.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.model.PageResult;
import com.scs.application.core.mvc.controller.BaseController;
import com.scs.application.modules.cert.entity.CertificateRepository;
import com.scs.application.modules.cert.request.OverallViewerQueryRequest;
import com.scs.application.modules.cert.service.OverallViewerService;
import com.scs.application.modules.cert.vo.OverAllCatalog;
import com.scs.application.modules.cert.vo.OverAllManufacturer;
import com.scs.application.modules.cert.vo.OverAllMaterial;
import com.scs.application.modules.cert.vo.OverAllSupplier;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 资质全景视图 controller
 */
@AllArgsConstructor
@RestController
@RequestMapping("/cert/overall_viewer")
public class OverallViewerController extends BaseController {

    private final OverallViewerService overallViewerService;

    @GetMapping("/list_supplier_cert_cnt")
    public CommonResult listSupplierCertCnt() {
        List<OverAllSupplier> list = overallViewerService.listSupplierCertCnt();
        return CommonResult.ok("查询成功", list);
    }

    @GetMapping("/list_supplier_by_supplier")
    public CommonResult listCurrentSupplierCertCnt() {
        List<OverAllSupplier> list = overallViewerService.listSupplierBySupplier();
        return CommonResult.ok("查询成功", list);
    }

    @GetMapping("/list_manufacturer_cert_cnt/{supplierId}")
    public CommonResult listManufacturerCertCnt(@PathVariable("supplierId") String supplierId) {
        List<OverAllManufacturer> list = overallViewerService.listManufacturerCertCnt(supplierId);
        return CommonResult.ok("查询成功", list);
    }

    @GetMapping("/list_catalog_cert_cnt/{supplierId}/{manufacturerId}")
    public CommonResult listCatalogCertCnt(@PathVariable("supplierId") String supplierId, @PathVariable("manufacturerId") String manufacturerId) {
        OverallViewerQueryRequest request = new OverallViewerQueryRequest();
        request.setManufacturerId(manufacturerId);
        request.setSupplierId(supplierId);
        List<OverAllCatalog> list = overallViewerService.listCatalogCertCnt(request);
        return CommonResult.ok("查询成功", list);
    }

    @GetMapping("/list_material_cert_cnt/{catalogId}/{manufacturerId}")
    public CommonResult listMaterialCertCnt(@PathVariable("catalogId") String catalogId, @PathVariable("manufacturerId") String manufacturerId) {
        OverallViewerQueryRequest request = new OverallViewerQueryRequest();
        request.setManufacturerId(manufacturerId);
        request.setCatalogId(catalogId);
        List<OverAllMaterial> list = overallViewerService.listMaterialCertCnt(request);
        return CommonResult.ok("查询成功", list);
    }

    /**
     * 全景视图查询
     *
     * @param request
     * @return
     */
    @GetMapping("/page_over_all")
    public PageResult pageOverAll(OverallViewerQueryRequest request) {
        IPage<CertificateRepository> page = overallViewerService.pageOverAll(request);
        return PageResult.ok("查询成功", page.getRecords(), page.getTotal());
    }

    /**
     * 根据查询条件列出当前医院下的资质信息
     *
     * @param request
     * @return
     */
    @GetMapping("/hospital/list")
    public CommonResult list(OverallViewerQueryRequest request) {
        List<CertificateRepository> list = overallViewerService.listForHospital(request);
        return PageResult.ok("查询成功", list);
    }

    @GetMapping("/list_manufacturer_by_supplier")
    public CommonResult listManufacturerBySupplier() {
        List<OverAllManufacturer> list = overallViewerService.listManufacturerBySupplier();
        return CommonResult.ok("查询成功", list);
    }

    @GetMapping("/list_catalog_by_supplier/{manufacturerId}")
    public CommonResult listCatalogForSupplier(@PathVariable("manufacturerId") String manufacturerId) {
        List<OverAllCatalog> list = overallViewerService.listCatalogForSupplier(manufacturerId);
        return CommonResult.ok("查询成功", list);
    }

    @GetMapping("/list_material_by_supplier/{catalogId}/{manufacturerId}")
    public CommonResult listMaterialForSupplier(@PathVariable("catalogId") String catalogId, @PathVariable("manufacturerId") String manufacturerId) {
        List<OverAllMaterial> list = overallViewerService.listMaterialForSupplier(catalogId, manufacturerId);
        return CommonResult.ok("查询成功", list);
    }

    /**
     * 全景视图查询
     *
     * @param request
     * @return
     */
    @GetMapping("/page_over_all_for_supplier")
    public PageResult pageOverAllForSupplier(OverallViewerQueryRequest request) {
        IPage<CertificateRepository> page = overallViewerService.pageOverAllForSupplier(request);
        return PageResult.ok("查询成功", page.getRecords(), page.getTotal());
    }

}
